package com.swsc.solarverse.dao.mapper.forward;

import com.swsc.solarverse.dao.entity.forward.ForwardStringDataCurrentdayDO;
import org.apache.ibatis.annotations.Insert;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author AutoGenerator
 * @since 2024-05-06
 */
@org.apache.ibatis.annotations.Mapper
public interface ForwardStringDataCurrentdayMapper extends com.swsc.solarverse.common.mybatis.BasePlusMapper<com.swsc.solarverse.dao.entity.forward.ForwardStringDataCurrentdayDO> {
    @org.apache.ibatis.annotations.Update(value = "TRUNCATE TABLE solar_forward_string_data_currentday")
    void truncate();

    @org.apache.ibatis.annotations.Select(value = "SELECT max(data_time) FROM solar_forward_string_data_currentday WHERE organ_no = #{organNo}")
    LocalDateTime maxDataTimeByOrgan(@org.apache.ibatis.annotations.Param("organNo") Integer organNo);

    @org.apache.ibatis.annotations.Select(value = "SELECT max(data_time) FROM solar_forward_string_data_currentday WHERE organ_no = #{organNo} and data_time >= #{dataTimeGe} and data_time < #{dataTimeLt}")
    LocalDateTime maxDataTimeByOrganAndTimeRange(@org.apache.ibatis.annotations.Param("organNo") Integer organNo,
                                                 @org.apache.ibatis.annotations.Param("dataTimeGe") LocalDateTime dataTimeGe,
                                                 @org.apache.ibatis.annotations.Param("dataTimeLt") LocalDateTime dataTimeLt);

    @org.apache.ibatis.annotations.Select(value = "SELECT max(data_time) FROM solar_forward_string_data_currentday")
    LocalDateTime maxDataTime();

    @Insert(value = {
            "<script>",
            "INSERT IGNORE INTO solar_forward_string_data_currentday (`id`,`tenant_no`,`organ_no`,`device_pid`,`device_id`,`device_name`,`device_code`,`voltage`,`electric_current`,`create_time`,`data_time`) VALUES ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(#{item.id}, #{item.tenantNo}, #{item.organNo}, #{item.devicePid}, #{item.deviceId}, #{item.deviceName}, #{item.deviceCode}, #{item.voltage}, #{item.electricCurrent}, #{item.createTime}, #{item.dataTime})",
            "</foreach>",
            "</script>"
    })
    int insertIgnoreBatch(java.util.List<com.swsc.solarverse.dao.entity.forward.ForwardStringDataCurrentdayDO> list);

    @Insert(value = {
            "<script>",
            "INSERT IGNORE INTO solar_forward_string_data_yesterday (`id`,`tenant_no`,`organ_no`,`device_pid`,`device_id`,`device_name`,`device_code`,`voltage`,`electric_current`,`create_time`,`data_time`) VALUES ",
            "<foreach collection='list' item='item' index='index' separator=','>",
            "(#{item.id}, #{item.tenantNo}, #{item.organNo}, #{item.devicePid}, #{item.deviceId}, #{item.deviceName}, #{item.deviceCode}, #{item.voltage}, #{item.electricCurrent}, #{item.createTime}, #{item.dataTime})",
            "</foreach>",
            "</script>"
    })
    int insertIgnoreBatchYesterday(java.util.List<com.swsc.solarverse.dao.entity.forward.ForwardStringDataCurrentdayDO> list);

    @org.apache.ibatis.annotations.Select(value = "SELECT * FROM solar_forward_string_data_currentday WHERE organ_no = #{organNo} and data_time >= #{dataTimeGe} and data_time < #{dataTimeLt}")
    List<ForwardStringDataCurrentdayDO> listByOrganAndTimeRange(@org.apache.ibatis.annotations.Param("organNo") Integer organNo,
                                                                @org.apache.ibatis.annotations.Param("dataTimeGe") LocalDateTime dataTimeGe,
                                                                @org.apache.ibatis.annotations.Param("dataTimeLt") LocalDateTime dataTimeLt);

    @org.apache.ibatis.annotations.Update(value = "TRUNCATE TABLE solar_forward_string_data_beforeyesterday")
    void truncateBeforeyesterday();

    @org.apache.ibatis.annotations.Update(value = "TRUNCATE TABLE solar_forward_string_data_yesterday")
    void truncateYesterday();

    @Insert(value = {
            "<script>",
            "INSERT IGNORE INTO solar_forward_string_data_beforeyesterday (`id`,`tenant_no`,`organ_no`,`device_pid`,`device_id`,`device_name`,`device_code`,`voltage`,`electric_current`,`create_time`,`data_time`) ",
            "SELECT `id`,`tenant_no`,`organ_no`,`device_pid`,`device_id`,`device_name`,`device_code`,`voltage`,`electric_current`,`create_time`,`data_time` FROM solar_forward_string_data_yesterday WHERE `data_time` &gt;= #{dataTimeGe} AND `data_time` &lt; #{dataTimeLt}",
            "</script>"
    })
    void copyYesterdayData2BeforeYesterday(@org.apache.ibatis.annotations.Param("dataTimeGe") LocalDateTime dataTimeGe,
                                           @org.apache.ibatis.annotations.Param("dataTimeLt") LocalDateTime dataTimeLt);

    @Insert(value = {
            "<script>",
            "INSERT IGNORE INTO solar_forward_string_data_yesterday (`id`,`tenant_no`,`organ_no`,`device_pid`,`device_id`,`device_name`,`device_code`,`voltage`,`electric_current`,`create_time`,`data_time`) ",
            "SELECT `id`,`tenant_no`,`organ_no`,`device_pid`,`device_id`,`device_name`,`device_code`,`voltage`,`electric_current`,`create_time`,`data_time` FROM solar_forward_string_data_currentday WHERE `data_time` &gt;= #{dataTimeGe} AND `data_time` &lt; #{dataTimeLt}",
            "</script>"
    })
    void copyCurrentdayData2Yesterday(@org.apache.ibatis.annotations.Param("dataTimeGe") LocalDateTime dataTimeGe,
                                      @org.apache.ibatis.annotations.Param("dataTimeLt") LocalDateTime dataTimeLt);
}
